﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSKD14:UIKDANSP
    { 
     
         public TSKD14()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VKDANSP();
            this.DataContext = MV; 
            InitializeComponent();
         }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            if (dwMain == null) ;
            if (dwMaster != null)
            {
                KEY = dwMaster["KDSANSPNA"].ToString();
            }
            else
            {
                KEY = "";
            }
        } 
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        public void Load()
        {
            if (KUNDNR.Trim().Length == 0)
                return;
            dwData = TBMain.NewRow();
            dwData["KDSMANDANT"] = app.Mandant;
            dwData["KDSKUNDNR"] =KUNDNR;
            SResult = ((VKDANSP)MV).QueryKDANSP(dwData, -1);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["KEY"] = Helpers.Helper.GetGB2312Value(row["KEY"].ToString());
                row["DES"] = Helpers.Helper.GetGB2312Value(row["DES"].ToString());
            }
            MergeData(SResult,false);
            Locate("KEY", ORDERNUM);
        }
        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
            Locate("KEY", ORDERNUM);
        }
        public override void OnKUNDNRChg(string value)
        {
            TBMain.Clear();
            if (KUNDNR.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["KDSMANDANT"] = app.Mandant;
            dwData["KDSKUNDNR"] = KUNDNR.Substring(0, 8);
            SResult = ((VKDANSP)MV).QueryKDANSP(dwData, -1);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["DES"] = Helpers.Helper.GetGB2312Value(row["DES"].ToString());
            }
            MergeData(SResult, false);
        } 
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                Load();
            }
            else
            {
                VICC_WFEVENTS.SVWF.KD02(this.RUNID);
            }
            base.ManageCommand(sender, e);
        }
        
    }
}
